package com.example.demo.controller;

import com.example.demo.modal.Principle;
import com.example.demo.service.PrincipleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/principle")
public class PrincipleController {
    @Autowired
    private PrincipleService PrincipleService;

    @GetMapping
    String action() {
        return "principle";
    }

    @PostMapping(value = "/show")
    @ResponseBody
    public List<Principle> show() {
        return PrincipleService.selectAll();
    }

    @PostMapping(value = "/update")
    @ResponseBody
    public String updat(@RequestBody Principle  principle){
        PrincipleService.updateByPrimaryKey(principle);
        return "更改成功！";
    }

    @PostMapping("/delete")
    @ResponseBody
    public String delete(@RequestParam("id") int id){
        PrincipleService.deleteByPrimaryKey(id);
        return "删除成功！";
    }

    @PostMapping("/save")
    @ResponseBody
    public String save(@RequestBody Principle principle){
        PrincipleService.save(principle);
        return "保存成功！";
    }

    @PostMapping("/max")
    @ResponseBody
    public int maxId(){
        return PrincipleService.selectMaxId();
    }

    @PostMapping("/find/princId")
    @ResponseBody
    public List<Principle> find_princId(@RequestParam("princId") int princId){
        return PrincipleService.findByprincId(princId);
    }

    @PostMapping("/find/variaAccou")
    @ResponseBody
    public List<Principle> find_variaAccou(@RequestParam("variaAccou") String variaAccou){
        return PrincipleService.findByvariaAccou(variaAccou);
    }

    @PostMapping("/find/calcuStyle")
    @ResponseBody
    public List<Principle> find_calcuStyle(@RequestParam("calcuStyle") String calcuStyle){
        return PrincipleService.findBycalcuStyle(calcuStyle);
    }

    @PostMapping("/find/princName")
    @ResponseBody
    public List<Principle> find_princName(@RequestParam("princName") String princName){
        return PrincipleService.findByprincName(princName);
    }

    @PostMapping("/find/nameEngli")
    @ResponseBody
    public List<Principle> find_nameEngli(@RequestParam("nameEngli") String nameEngli){
        return PrincipleService.findBynameEngli(nameEngli);
    }

    @PostMapping("/find/variaNo1")
    @ResponseBody
    public List<Principle> find_variaNo1(@RequestParam("variaNo1") String variaNo1){
        return PrincipleService.findByvariaNo1(variaNo1);
    }

    @PostMapping("/find/variaNo2")
    @ResponseBody
    public List<Principle> find_variaNo2(@RequestParam("variaNo2") String variaNo2){
        return PrincipleService.findByvariaNo2(variaNo2);
    }

    @PostMapping("/find/variaNo3")
    @ResponseBody
    public List<Principle> find_variaNo3(@RequestParam("variaNo3") String variaNo3){
        return PrincipleService.findByvariaNo3(variaNo3);
    }

    @PostMapping("/find/variaNo4")
    @ResponseBody
    public List<Principle> find_variaNo4(@RequestParam("variaNo4") String variaNo4){
        return PrincipleService.findByvariaNo4(variaNo4);
    }
}
